# Windows停止脚本
import os
import re

port: int = 3123

pattern = r"\s+"

result = os.popen("netstat -ano | findstr " + str(port))
lines = result.readlines()
if (len(lines) > 0):
    firrtline = lines[0]
    split = re.split(pattern, firrtline)
    address = split[2]
    if len(split) > 2 and (address == "0.0.0.0:" + str(port)
                           or
                           address == "127.0.0.1:" + str(port)):
        pid = split[5]
        print("进程ID: " + pid)
        os.popen("taskkill /pid " + pid + " /F")
        print("已kill")
